// Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once
#include <string>
#include <vector>
#include <memory>
#include <utility>
#include <ctime>

#include <opencv2/opencv.hpp>
#include <paddle_inference_api.h>

#include "base_util/utils.h"
#include "pdmodel_manager.h"


namespace paddle_infer {

class CrnnResizeImg;
class Normalize;
class Permute;
class OCRPostProcessor;

class OCRRecognizer {
public:
  OCRRecognizer(LogInfo *lg);

  int Run(cv::Mat& img, 
          std::vector<BaseInfoPD*> &rec_ifo, 
          PDModelManager *mng,
          int md_idx);

private:

  int RunCRNN(cv::Mat& img, 
              std::vector<BaseInfoPD*> &rec_ifo, 
              PDModelManager *mng,
              int md_idx);
  
private:

  std::vector<float> mean_ = {0.5f, 0.5f, 0.5f};
  std::vector<float> scale_ = {1 / 0.5f, 1 / 0.5f, 1 / 0.5f};
  bool is_scale_ = true;
  // pre-process
  CrnnResizeImg *resize_op_;
  Normalize *normalize_op_;
  Permute *permute_op_;

  // post-process
  OCRPostProcessor *post_processor_;

  int min_text_height = 26;

  LogInfo *log_ifo;

}; // class CrnnRecognizer

} // namespace paddle_infer

